package midterm;

import static org.junit.Assert.*;

import java.util.*;

import org.junit.Before;
import org.junit.Test;

public class TwittererTest {

	Twitterer [] originalTwits = {
			new Twitterer("Kira", "Night", 1, 120),
			new Twitterer("Saryta", "Britney", 30, 10),
			new Twitterer("Demi", "Moo", 4, 6),
			new Twitterer("Rafa", "Nadal", 2, 30),
			new Twitterer("Ashton", "Kooch", 7, 12)
			};

	@Test
	public void partA() {

		System.out.println("Part A");

		List<Twitterer> aList =
				new ArrayList<Twitterer>(Arrays.asList(originalTwits));

		aList.remove(new Twitterer("Saryta", "Moo", 7, 120));

		for(Twitterer who : aList) {
			System.out.println(who.getNic());
		}
		
		// Removes Saryta from the list, and then prints everyone out.

	}

	@Test
	public void partB() {

		System.out.println("Part B");

		List<Twitterer> sorter =
				new ArrayList<Twitterer>(Arrays.asList(originalTwits));

		sorter.remove(Collections.max(sorter));

		for(Twitterer who : sorter) {
			System.out.println(who.getTweets());
		}
		
		// Removes the Twitterer who has the most followers, then prints out the rest.

	}

	@Test
	public void partC() {

		System.out.println("Part C");

		List<Twitterer> twits = new ArrayList<Twitterer>();
		Iterator<Twitterer> twIter = twits.iterator();
		
		while(twIter.hasNext()) {
			Twitterer aGolfer = twIter.next();
			if(aGolfer.getFollowers() > 10) {
				continue;
			}
			
			twIter.remove();
		}

		for(Twitterer who : twits) {
			System.out.println(who.getTweets());
		}
		
		// Creates a new ArrayList but doesn't insert any objects into the list, so we just get Part C printed.

	}

	@Test
	public void partD() {

		System.out.println("Part D");

		// Hint: like putting an extra Comparator parameter on Collections.sort

		Set<Twitterer> aSet = new TreeSet<Twitterer>(new Comparator<Twitterer>() {
			public int compare(Twitterer a, Twitterer b) {
				String aName = a.getActualName();
				String bName = b.getActualName();
				return aName.compareTo(bName);
			}
		});

		for(Twitterer who : originalTwits) {
			aSet.add(who);
		}

		// *** See Question 2

		aSet.remove(new Twitterer("Ashton", "Britney", 4, 10));
		aSet.add(new Twitterer("Heidi", "Spencer", 103, 16));

		for(Twitterer who : aSet) {
			System.out.println(who);
		}
		// Printing starts at the far left of the TreeSet, then moves up through the parents,
		// printing them out!
	}

	@Test
	public void partE() {

		System.out.println("Part E");

		Map<String, Twitterer> aMap = new HashMap<String, Twitterer>();

		aMap.put("Celeb", originalTwits[2]);
		aMap.put("Celeb", originalTwits[3]);
		aMap.put("Pease", new Twitterer("Demi", "Moo", 4, 6));

		for(Twitterer who : aMap.values()) {
			System.out.println(who);
		}
		
		// Prints out three users, the two from index positions 2 and 3 in originalTwits, and the
		// new twitterer that looks like Demi. No overwriting is done because the new Demi has
		// a different key. 'Celeb' however appears twice, and since HashMaps OVERWRITE
		// and don't DROP DUPLICATES, Moo gets overwritten by Nadal.
	}

	@Test
	public void partF() {

		System.out.println("Part F");

		Map<Twitterer, Twitterer> aMap = new HashMap<Twitterer, Twitterer>();

		for(Twitterer who : originalTwits) {
			aMap.put(who, who);
		}

		Twitterer reTwit = new Twitterer("Rafa", "Kooch", 30, 10);
		aMap.put(reTwit, reTwit);

		for(Twitterer who : aMap.values()) {
			System.out.println(who);
		}
		
		// Every entry has the same key and value, being the object that the value
		// contains. When 'Kooch' gets added though, the compareTo starts with followers,
		// so Britney gets overwritten. I think...
		
		// I was right about Britney being overwritten, but the order's weird.
		
		// All wrong, re-do the unit test and read it over...and don't forget to print
		// out all the Java code you need for tomorrow!

	}

	@Test
	public void partG() {

		System.out.println("Part G");

		Set<Twitterer> people = new TreeSet<Twitterer>();
		people.addAll(Arrays.asList(originalTwits));

		people.add(new Twitterer("Kira", "Britney", 4, 6));
		people.add(new Twitterer("Tiger", "Ford", 345, 5));
		people.add(new Twitterer("Demi", "Nadal", 4, 6));

		for(Twitterer who : people) {
			System.out.println(who);
		}
		
		// Another TreeSet, so duplicates don't overwrite.
		// 

	}

}